package extract;

import control.CConnection;
import control.CState;
import model.State;
import java.util.StringTokenizer;
import java.io.*;
import java.sql.*;

public class ExtractState {
	public static void main(String args[]) {
		CConnection cn = new CConnection();
		
		try {
			cn.createConnection();
			CState cs = new CState(cn);
			
			BufferedReader input = new BufferedReader(new FileReader("data/brazilianStates.txt"));
			String line;

			for(int i = 1; (line = input.readLine()) != null; i++) {
				StringTokenizer st = new StringTokenizer(line, ";");
				
				cs.create(new State(i, st.nextToken()));
			}
			
			System.out.println("States added successfully.");
		}
		catch (ClassNotFoundException e) {
			System.err.println("Couldn't connect to Derby Database.");
		}
		catch (SQLException e) {
			System.err.println("Error in SQL Statement.");
		}
		catch (FileNotFoundException e) {
			System.err.println("File not found!");
		}
		catch (IOException e) {}
	}
}